package com.gosophia.reportData.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.reportData.dto.ApprovalReportJobDTO;
import com.gosophia.reportData.ws.LaunchReportWebService;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;

/**
 * 审核结果，通过或退回
 * 
 * @author tianchunyu
 * 
 */
@Controller
@Scope("prototype")
public class ApprovalResultAction extends BaseSupportAction {

	/**
     * 
     */
	private static final long serialVersionUID = 1L;
	private static final String PASSED = "通过";
	private static final String BACKED = "退回";

	@Autowired
	private LaunchReportWebService LaunchReportWebService;

	private ApprovalReportJobDTO approvalReportJobDto;
	
	private String approvalState;

	private Long jobId;
	
	private String fromFlag;

	@Override
	public String _execute() throws Exception {
		UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
				.getContext().getAuthentication().getPrincipal();
		Long userInfoId = userDetails.getUserAccountDTO().getUserInfoDTO()
				.getUserInfoId();

		// 审核结果标识(approvalState)，通过：Y 退回：N
		String operationName = "";
		if(approvalState.equals("Y")){
			operationName = this.PASSED;
		}else{
			operationName = this.BACKED;
		}
		LaunchReportWebService.approvalReporting(approvalReportJobDto, jobId,
				userInfoId, operationName);
		super.getRequestResult().setMessage("审核完成");
		super.getRequestResult().setRsltCode("0");
		ActionContext.getContext().getSession().put("_lastOpResult",
				super.getRequestResult());
		return SUCCESS;
	}

	public Long getJobId() {
		return jobId;
	}

	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}

	public ApprovalReportJobDTO getApprovalReportJobDto() {
		return approvalReportJobDto;
	}

	public void setApprovalReportJobDto(ApprovalReportJobDTO approvalReportJobDto) {
		this.approvalReportJobDto = approvalReportJobDto;
	}

	public String getApprovalState() {
		return approvalState;
	}

	public void setApprovalState(String approvalState) {
		this.approvalState = approvalState;
	}

    public String getFromFlag() {
        return fromFlag;
    }

    public void setFromFlag(String fromFlag) {
        this.fromFlag = fromFlag;
    }
}
